package mp

import (
	"duoke/model"
	"duoke/service"
	"duoke/utils/gconv"
	"duoke/utils/request"
	"duoke/utils/response"
	"duoke/utils/valid"
	"github.com/gin-gonic/gin"
	"github.com/go-playground/validator/v10"
)

var TencentIm = new(tencentImCtl)

type tencentImCtl struct{}

func (ctl *tencentImCtl) BindUser(c *gin.Context) {
	req := request.JsonMap(c)
	bindId := gconv.Int(req["bind_id"])
	if bindId == 0 {
		response.Error(c, "参数缺失【bind_id】", nil)
		return
	}
	user, err := service.TencentIm.BindUser(c, bindId)
	if err != nil {
		response.Error(c, err.Error(), nil)
		return
	}
	response.Success(c, "success", user)
}
func (ctl *tencentImCtl) SendMsg(c *gin.Context) {
	// MsgType 表示消息元素的类型
	var req model.SendFromMsgRequest
	if err := c.ShouldBind(&req); err != nil {
		response.Error(c, valid.GetError(err.(validator.ValidationErrors), req), nil)
		return
	}
	err := service.TencentIm.SendMsg(c, &req)
	if err != nil {
		response.Error(c, err.Error(), nil)
		return
	}
	response.Success(c, "success", nil)
}
func (ctl *tencentImCtl) AdminGeotropism(c *gin.Context) {
	var req model.AdminGeotropismReq
	if err := c.ShouldBind(&req); err != nil {
		response.Error(c, valid.GetError(err.(validator.ValidationErrors), req), nil)
		return
	}
	geotropism, err := service.TencentIm.AdminGeotropism(c, &req)
	if err != nil {
		response.Error(c, err.Error(), nil)
		return
	}
	response.Success(c, "success", geotropism)
	return
}
func (ctl *tencentImCtl) DeleteMsg(c *gin.Context) {
	var req model.DeleteMsgReq
	if err := c.ShouldBind(&req); err != nil {
		response.Error(c, valid.GetError(err.(validator.ValidationErrors), req), nil)
		return
	}
	err := service.TencentIm.DeleteMsg(c, &req)
	if err != nil {
		response.Error(c, err.Error(), nil)
		return
	}
	response.Success(c, "success", nil)
}
func (ctl *tencentImCtl) AdminMsgWithdraw(c *gin.Context) {
	var req model.AdminMsgWithdrawReq
	if err := c.ShouldBind(&req); err != nil {
		response.Error(c, valid.GetError(err.(validator.ValidationErrors), req), nil)
		return
	}
	err := service.TencentIm.AdminMsgWithdrawReq(c, &req)
	if err != nil {
		response.Error(c, err.Error(), nil)
		return
	}
	response.Success(c, "success", nil)
}
